/*
var goodsId=$("#rightMenuGoodsId").val();
		if(isNaN(goodsId)){
			goodsId=-1;
		}//,{goodsId:goodsId}
*/
/**
 * 网站根
 */
var _appRoot="";
/**
 * 单个商品查询地址
 */
var _queryGoods=_appRoot+"/search/";
/**
* 问答详细地址
*/
var _queryQuestion = _appRoot+"/wd/";
/**
 * 条件查询地址
 */
var _queryCondition=_appRoot+"/browse/ajaxCondition";

/**
 * 图片服务器地址
 */
var _picRoot="http://115.29.210.249/iteasyPic";
/*验证码图片地址*/
var _validCodeSrc=_appRoot+"/userCenter/imageCode";

$(document).ready(function(){
	// 全选
	$('#selectAll').click(function() {
		$('#checkbox').each(function(){
			this.checked = "checked";
		});
	});
	
	if($(".quick_link_mian").length>0){
		
	
	$(".quick_links_panel li").mouseenter(function(){
		$(this).children(".mp_tooltip").animate({left:-92,queue:true});
		$(this).children(".mp_tooltip").css("visibility","visible");
		$(this).children(".ibar_login_box").css("display","block");
	});
	$(".quick_links_panel li").mouseleave(function(){
		$(this).children(".mp_tooltip").css("visibility","hidden");
		$(this).children(".mp_tooltip").animate({left:-121,queue:true});
		$(this).children(".ibar_login_box").css("display","none");
	});
	$(".quick_toggle li").mouseover(function(){
		$(this).children(".mp_qrcode").show();
	});
	$(".quick_toggle li").mouseleave(function(){
		$(this).children(".mp_qrcode").hide();
	});

// 元素以及其他一些变量
var eleFlyElement = document.getElementById("flyItem"), eleShopCart = document.getElementById("shopCart");
var numberItem = 0;
// 抛物线运动
var myParabola = funParabola(eleFlyElement, eleShopCart, {
	speed: 400, //抛物线速度
	curvature: 0.0008, //控制抛物线弧度
	complete: function() {
		eleFlyElement.style.visibility = "hidden";
		eleShopCart.getElementsByTagName("span").innerHTML = ++numberItem;
	}
});
// 绑定点击事件
if (eleFlyElement && eleShopCart) {
	
	[].slice.call(document.getElementsByClassName("btnCart")).forEach(function(button) {
		button.addEventListener("click", function(event) {
			// 滚动大小
			var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft || 0,
			    scrollTop = document.documentElement.scrollTop || document.body.scrollTop || 0;
			eleFlyElement.style.left = event.clientX + scrollLeft + "px";
			eleFlyElement.style.top = event.clientY + scrollTop + "px";
			eleFlyElement.style.visibility = "visible";
			
			// 需要重定位
			myParabola.position().move();			
		});
	});
}
	}

	
	if(typeof(whenDocumentReady)=="function"){
		whenDocumentReady();
	}

	if(typeof(whenDocumentReady2)=="function"){
		whenDocumentReady2();
	}

	if(typeof(whenDocumentReady3)=="function"){
		whenDocumentReady3();
	}
	
	if(typeof(whenDocumentReady4)=="function"){
		whenDocumentReady4();
	}
	//解决ie不支持placeholder
	if((navigator.userAgent.indexOf("MSIE 7.0")>0)||(navigator.userAgent.indexOf("MSIE 8.0")>0)||(navigator.userAgent.indexOf("MSIE 9.0")>0)){
	$(".placeHolder").each(function(){
		if($(this).val()==""){
			$(this).next(".tipPlace").show();
		}
	});
	$(".placeHolder").keydown(function(){
		var inputNum=$(this).val().length;
		if(inputNum==0){
		$(this).next(".tipPlace").show();
		}
		else{
		$(this).next(".tipPlace").hide();
		}
	});
	$(".placeHolder").keyup(function(){
		var inputNum=$(this).val().length;
		if(inputNum==0){
		$(this).next(".tipPlace").show();
		}
		else{
		$(this).next(".tipPlace").hide();
		}
	});
	$(".tipPlace").click(function(){
		$(this).prev(".placeHolder").focus();
	});
	}
	getLeftPosition();
	loadingShoppingCart();
});
//获取左侧悬浮窗的位置
function getLeftPosition(){
	if($("#leftNavigation").length>0){
		var bodyWidth=$(document.body).width();
		if(bodyWidth>1500){
			$("#leftNavigation").css("left",(bodyWidth-1200)/2-140+"px");
		}
	}
}
(function($){
	$.fn.hoverForIE6=function(option){
		var s=$.extend({current:"hover",delay:10},option||{});
		$.each(this,function(){
			var timer1=null,timer2=null,flag=false;
			$(this).bind("mouseover",function(){
				if (flag){
					clearTimeout(timer2);
				}else{
					var _this=$(this);
					timer1=setTimeout(function(){
						_this.addClass(s.current);
						flag=true;
					},s.delay);
				}
			}).bind("mouseout",function(){
				if (flag){
					var _this=$(this);timer2=setTimeout(function(){
						_this.removeClass(s.current);
						flag=false;
					},s.delay);
				}else{
					clearTimeout(timer1);
				}
			})
		})
	}
})(jQuery);


	/**
	 * 课程难度解析
	 */
	function courseHardConvert(){
		$(".courseHard").each(function(){
			var number=$(this).html().trim();
			/*if(number=="" || number==null || isNaN(number)){
				$(this).html("简单");
				return ;
			}*/
			var str="";
			switch (parseInt(number)){
			case 0:str="初级";break;
			case 1:str="中级";break;
			case 2:str="高级";break;
			case 3:str="专业";break;
			default :str="初级";
			}
			$(this).html(str);
		});
	}
	
	/**
	 * 分类查询页面的条件选项点击事件注册
	 */
	function clickRegisterForQueryCategoryAttributes(){
		$(".attributesItem").click(function(){
			var data=$(this).attr("data");
			var index=$(this).attr("dataIndex");
			
			if(data=="-1"){
				return dropConditionForQueryCategory(index);
			}
			if(index==-1){//点击匹配到的分类
				$("#top_categoryId").val(data);
				var text=$(this).text();
				var i=text.lastIndexOf(">");
				$("#top_categoryName").val(text.substr(i+1,text.length));
			}else if(index<3){ //点击分类
				$("#top_categoryId").val(data);
				$("#top_categoryName").val($(this).text());
			}else{//点击其他筛选条件
				$("#attribute"+index).val(data);
			}
			formSubmit();
		});
		$("#minPriceInput,#maxPriceInput").keyup(function(){
			var number=$(this).val();
			if(isNaN(number)){
				$(this).val(0);
			}
		});
		$("#priceZoneButton").click(function(){
			var minPrice=$("#minPriceInput").val();
			var maxPrice=$("#maxPriceInput").val();
			var val="";
			if(minPrice==""){
				minPrice="0";
			}
			if(maxPrice!=""){
				maxPrice="-"+maxPrice;
			}
			$("#attribute6").val(minPrice+maxPrice);
			formSubmit();
		});
		$(".orderByItem").click(function(){
			var data=$(this).attr("data");
			$("#top_orderBy").val(data);
			formSubmit();
		});
	}
	
	/**
	 * 分类查询页面的表单提交（已修改：将动作放到触发提交之后,现在等效于$("#queryForm").submit()）
	 */
	function formSubmit(){
		
		$("#queryForm").submit();
	}
	
	/**
	 * 分类查询页面表单提交事件
	 */
	function onFormSubmit(){
		var action=$("#queryForm").attr("action");
		if($("#top_categoryId").val()==1&&$("#top_categoryName").val()==1){
			if(action!="../search.htm"/*tpa=http://www.yxit.net/search.htm*/){
				var href=window.location.pathname;
				$("#queryForm").attr("action",href);
			}
		}else{
			var goodsType=$("#top_goodsType").val();
			if(goodsType==null || goodsType==""|| isNaN(goodsType) || goodsType=="-1" ){
				goodsType="ok";
			}
			$("#queryForm").attr("action",action+"/"+$("#top_categoryId").val()+goodsType+".htm");
		}
	}
	
	/**
	 * 分类查询页面筛选条件生成
	 */
	_goodsTypeValueList={attribute4:["技能培训","考试认证","其他","全部"],attribute5:["在线学习","面授","1对1辅导","视频","其他","全部","考证"]}
	function createConditionForQueryCategory(){
		var html="<a href='http://www.yxit.net/js/"+_appRoot+"/'>IT易学网</a><span> > </span>";
		var titleText="",seoWords="";seoDescription="";
		html+="<a href='http://www.yxit.net/js/"+_appRoot+"/search.htm"+"'>课程分类</a>";
		var goodsType=$("#top_goodsType").val();
		var categoryName=$("#top_categoryName").val();
		switch(parseInt(goodsType)){
		case 0:html+=" > <a href='http://www.yxit.net/js/"+_appRoot+"/online.htm"+"'>在线学习</a>";
			titleText="IT在线学习课程_IT远程授课-IT易学网";
			seoWords="IT在线学习课程,ocp在线培训,it远程授课,ccna在线培训,oracle认证培训,hcna在线培训,RHCE在线培训,C语言在线学习,软件开发在线学习";
			seoDescription="IT易学网在线学习课程,IT精英讲师在线指导学习,it远程同步授课,让您足不出户,亦可成为IT大神。";
			break;
		case 1:html+=" > <a href='http://www.yxit.net/js/"+_appRoot+"/facedirect.htm"+"'>面授</a>";
			titleText="IT面授学习课程_网络认证工程师面授培训-IT易学网";
			seoWords="it面授学习课程,java培训,PHP培训,hcnp培训,oracle培训,html语言培训,ccnp认证培训,网页开发面授,软件开发面授,C语言培训";
			seoDescription="IT易学网面授学习课程,可同城/异地开课,授课范围涵盖IT行业所有领域,包括java培训,PHP培训,IT国际认证,网页开发,软件开,C语言等。";
			break;
		case 2:html+=" > <a href='http://www.yxit.net/js/"+_appRoot+"/o2o.htm"+"'>1对1辅导</a>";
			titleText="IT学习一对一辅导_私人定制课程-IT易学网";
			seoWords="it一对一授课,it一对一辅导,平面设计辅导,it考试认证辅导,ccna远程培训,oracle远程培训,MCSE远程培训,私人定制课程";
			seoDescription="IT易学网高端讲师一对一辅导,手把手教你学IT,可根据您的个人学习需求,私人定制专属于您的课程。IT易学网只做您合适的。";
			break;
		case 3:html+=" > <a href='http://www.yxit.net/js/"+_appRoot+"/video.htm"+"'>视频</a>";
			titleText="IT视频教程_IT课程视频_IT自学视频-IT易学网";
			seoWords="IT课程视频,IT自学视频,IT视频教程,Java视频教程,CCNA视频教程,HTML视频教程,PS视频教程,编程自学视频教程";
			seoDescription="IT易学网免费视频教程,提供所有IT学习视频,包括Java,CCNA,PS,oracle,hcnp,HTML,ps,编程等等。";
			break;
		case 6:html+=" > <a href='http://www.yxit.net/js/"+_appRoot+"/identify.htm"+"'>考证</a>";
			titleText="IT考证_IT认证考试-IT易学网帮你预约,考证无忧";
			seoWords="IT认证考试报名,IT厂商认证考试,ocp认证考试证,思科认证考试,oracle认证考试,华为认证考试,RHCE认证考试,微软认证考试";
			seoDescription="IT考证、IT认证考试报名来IT易学网!报名即送题库!您只需做好备考,IT易学网专业老师帮您快速预约,让您考证无忧。";
			break;
		case 4:html+=" > <a href='http://www.yxit.net/js/"+_appRoot+"/kejian.htm"+"'>课件</a>";
			titleText="IT入门教程_IT教学课件_oracle视频教程-IT易学网";
			seoWords="it教学课件,it学习课件,it入门教程,oracle视频教程,C++教程课件,Java视频课件,PHP教程课件,ccna教程课件,ps教程课件";
			seoDescription="内涵IT技术各大领域的学习课件和视频教程,可单独买卖,包括oracle视频教程,C++教程课件,Java视频课件,各大国际IT认证课件等等。";
			break;
		case 5:html+=" > <a href='http://www.yxit.net/js/"+_appRoot+"/tiku.htm"+"'>题库</a>";
			titleText="IT考试题库_ocp题库_ccna题库-IT易学网提供最新IT题库";
			seoWords="IT考试题库,IT最新考证题库,免费IT考证题库,CCNA题库,HCNA题库，CCNP题库,HCNP题库,OCP题库,RHCA题库,RHCE题库";
			seoDescription="IT易学网旨在为广大IT技术爱好者提供更便捷、更优质的IT服务,内含思科、华为、红帽、微软、Oracle等各大IT认证最新题库,低价格高质量!";
			break;
		}
		//三级分类的选择条件
		if($("#categoryLevel1").hasClass("hidden") && $("#categoryLevel0").length==0){
			var selected=$("#categoryLevel1 .selected");
			html+="<span> > </span><a href='javascript:void(0);' onclick='dropConditionForQueryCategory(0,$(this))'>"+selected.html()+"</a>";
			if(titleText==""){
				titleText+=selected.html();
			}else{
				titleText+=","+selected.html();
			}
			
		}
		if($("#categoryLevel2").hasClass("hidden") && $("#categoryLevel0").length==0){
			var selected=$("#categoryLevel2 .selected");
			html+="<span> > </span><a href='javascript:void(0);' onclick='dropConditionForQueryCategory(1,$(this))'>"+selected.html()+"</a>";
			titleText+=","+selected.html();
		}
		if($("#categoryLevel3").hasClass("hidden") && $("#categoryLevel0").length==0){
			var selected=$("#categoryLevel3 .selected");
			html+="<span> > </span><a href='javascript:void(0);' onclick='dropConditionForQueryCategory(2,$(this))'>"+selected.html()+"</a>";
			titleText+=","+selected.html();
		}
		
		//其他条件
		for(var i=3;i<7;i++){
			var value=$("#attribute"+(i)).val();
			if(value==""){
				continue;
			}
			if(i==4||i==5){
				value=_goodsTypeValueList["attribute"+i][value];
				//titleText+=","+value;
			}
			html+="<span> > </span><a id='currentValue"+(i)+"' href='javascript:void(0);' onclick='dropConditionForQueryCategory("+(i)+")'>"+value+"</a>";
	
			$("#attributesUL"+i).addClass("hidden");
		}
		if($("#attribute3").val()!=""){
			titleText+=","+$("#attribute3").val();
		}
		$("#goodsAttributesDt").html(html);
		$("title").html("IT易学网-"+titleText);
		$("meta[name='keywords']").attr("content",seoWords);
		$("meta[name='description']").attr("conetnt",seoDescription);
	}
	
	/**
	 * 筛选条件取消
	 */
	function dropConditionForQueryCategory(index,thisA){
		if(index==0){//一级分类的全部
			/*$("#top_categoryId").val("1");
			$("#top_categoryName").val("1");
			formSubmit();*/
			window.location.href=_appRoot+$(thisA).prevAll("a").attr("href");
			return;
		}else if(index==1){//二级分类的全部
			$("#top_categoryId").val(category[_L1].id);
			$("#top_categoryName").val(category[_L1].name);
			formSubmit();
			return ;
		}else if(index==2){//三级分类的全部
			$("#top_categoryId").val(category[_L1].list[_L2].id);
			$("#top_categoryName").val(category[_L1].list[_L2].name);
			formSubmit();
			return ;
		}
		$("#attribute"+index).val("");
		formSubmit();
		return ;
	}
	
	/**
	 * 条件选项点击事件,查询级联条件
	 */
	function conditionItemClickRegister(){
		$("li.select-items").click(function(){
			conditionItemClickFunction(this);
		});
		
	}
	
	/**
	 * 条件选项点击事件响应函数
	 */
	function conditionItemClickFunction(obj){
		var id=$(obj).closest("div.select-main").prev().attr("id");
		var value=$(obj).html();
		if(value=="未选择"){
			return ;
		}
		var nextIdIndex=(parseInt(id.substr(9,1) )+1);
		//nextId需对应bean中的属性名
		var nextId="condition"+nextIdIndex;
		var goodsId=$("#goodsId").val();
		var data={groupBy:nextId,
						condition1:nextIdIndex>1?$("#condition1").val():"",
						condition2:nextIdIndex>2?$("#condition2").val():"",
						condition3:nextIdIndex>3?$("#condition3").val():"",
						condition4:nextIdIndex>4?$("#condition4").val():"",
						condition5:nextIdIndex>5?$("#condition5").val():"",
						condition6:nextIdIndex>6?$("#condition6").val():""
		};
		$.post(_queryCondition+"/"+goodsId,data,function(map){
			//TODO 自动选择单项
			
			//var goodsType=$("#goodsType").val();
			if(map==null || map==""){
				alert("no return");
			}
			setMoreCondition(nextIdIndex,map);
			
			
		},"json");
	}
	
	/**
	 * 如果只有一个结果，则设置下一级联菜单
	 */
	function setMoreCondition(nextIdIndex,map){
		var nextId="condition"+nextIdIndex;
		var list=map["list"+nextIdIndex];
		if(list==null){
			return ;
		}
		var length=list.length;
		
		var tag=$("#"+nextId).hasClass("conditionItem")?true:false;
		var uiSelectAttribute=tag?"conditionItem":"";
		var unSelectOption=length==1?"":"<option value=''>未选择</option>";
		
		var html="<select id='"+nextId+"' class='ui-select "+uiSelectAttribute+"'>"+unSelectOption;
		for(var i=0;i<length;i++){
			html +="<option value='"+list[i][nextId]+"'>"+list[i][nextId]+"</option>";
		}
		html+="</select>";
		
		var prev=$("#"+nextId).prev();
		if(prev.length<1){
			$("#"+nextId).before("<input type='hidden' />");
			prev=$("#"+nextId).prev();
		}
		$("#"+nextId).next().remove();
		$("#"+nextId).remove();
		prev.after(html);
		uiSelectChangeRegister("#"+nextId);
		if(tag){
			$("#"+nextId).next().find("li.select-items").click(function(){
				conditionItemClickFunction(this);
			});
		}
		if(length==1){
			setMoreCondition(nextIdIndex+1,map);
		}
		
		
		
	}
	

	
	
	//获取用户列表
	function ajaxForQuestionUserList(showFirstPage){
		var categoryId=$("#wdUserListCategory").val();
		var page=$("#wdUserListPage").val();
		var orderFiled = $("#orderFiled").val();
		var orderType = $("#orderType").val();
		
		if(typeof(orderFiled)=="undefined" || orderFiled.length<=0){
			orderFiled = 0;
		}
		if(typeof(orderType)=="undefined" || orderType.length<=0){
			orderType = 0;
		}
		
		$.post(_appRoot+"/question/wdUserList",{categoryId:categoryId,page:page,showFirstPage:showFirstPage,orderFiled:orderFiled,orderType:orderType},function(result){
			if(result==null ||result.list==null){
				alert("error");
				return;
			}
			$("#wdUserListPage").val(result.page);
			var list=result.list;
			var html="";
			if(list.length>0){
				for(var i=0;i<list.length;i++){
					html+="<li><img src='"+_picRoot+list[i].userIco+"' height='64' width='64' />";
					html+="<p>用户名："+list[i].nickName+"</p>";
					html+="<div class='jianjie'><div class='jjjj'>简介：</div><div class='shuj'>"+list[i].description+"</div></div>";
					if(list[i].isOnline==1){
					html+="<a href='#0' onclick='askOnline2(\""+list[i].userId+"\",\""+list[i].nickName+"\");'>在线提问>></a></li>";
					}
					else if(list[i].isOnline==0){
					html+="<a href='#0' onclick='askOnline2(\""+list[i].userId+"\",\""+list[i].nickName+"\");'>离线留言>></a></li>";
					}
				}
			}else{
				html+="<div class='noUserList'>暂无数据，请换个分类试试!</div>";
			}
			$("#userListUl").html(html);
		},"json");
	}

	//商品数量变化
	function sumChange(obj){
		
		var price=obj.closest("li.lineItem").find(".price").html();
 		var sum=obj.find(".cartGoodsSum").val();
 		var money=parseToFen(price)*parseInt(sum);
 		obj.closest("li.lineItem").find(".money").html(parseToYuan(money));
 		countTotalMoney();
	}
	
	
	function sumChangeInShoppingCart(obj){
		var sum=obj.find(".cartGoodsSum").val();
		var cartId = obj.parent().attr("data");
		
		$.post(_appRoot+"/userCenter/udpateGoodsSum",{shoppingCartId:cartId,num:sum},function(data){
			if(data!=null && data.result==1){
				var price=obj.closest("li.lineItem").find(".price").html();
				var money=parseToFen(price)*parseInt(sum);
				obj.closest("li.lineItem").find(".money").html(parseToYuan(money));
				countTotalMoney();
				sum = 0;
				var goodsSum = $(".cartGoodsSum");
				for(var i=0;i<goodsSum.length;i++){
					sum+=parseInt($(goodsSum[i]).val());
				}
				
				$("#shoppingCart_sum").html(sum);
				$(".cart_top_num").html(sum);
				
				return;
			}else{
				clickautohide(data.message,3);
			}
		},"json");
		
		
		
	}
	

 	//计算结算金额总量
 	function countTotalMoney(){
 		var sum=0;
		$(".lineItem .check :checked").each(function(){
			var line=$(this).closest("li.lineItem");
			var money=line.find(".money").html();
			var integer=line.find(".integerInput").val();
			if(isNaN(integer) || integer==""){
				integer=0;
			}
			sum+=parseToFen(money)-parseInt(integer+"");
		});
		if(parseToYuan(sum)==0){
			$(".totalMoney").html("￥0.00");
		}else{
			$(".totalMoney").html("￥"+parseToYuan(sum)+"");
		}
		
 	}
 	//展示已收藏
	function show() {
		
		document.getElementById('div2').style.display = 'block'
		setTimeout(function(){
     		var obj = document.getElementById("div2");
     		obj.style.display = "none";
 		},500);
		
 	}
	
	
	//从购物车中移除商品
	function deleteFromShoppingCart(){
		var id=$("#currentLineId").val();
		var sum = $("#goodsSum_"+id).attr("data");
		
		$.post("deleteShoppingCart",{shoppingCartId:id},function(result){
			if(result!=null&&result.result==1){
				$("#lineItem_"+id).remove();
				var shoppingCart_sum = $("#shoppingCart_sum").html();
				$("#shoppingCart_sum").html(parseInt(shoppingCart_sum)-sum);
				countTotalMoney();
			}else if(result.message!=""){
				clickautohide(message,3);
			}
		},"json");
	}
	
	//移入收藏夹
	function addCollection(obj){
		if(obj.hasClass("alreadyDone")){
			return false;
		}
		var cartId=obj.closest(".lineItem").attr("data");
		//var goodsPriceId=obj.attr("data2");
		//var priceValue=obj.closest(".lineItem").find(".price").html();
		$.post("addUserCollection",{cartId:cartId},function(result){
			if(result!=null&&result.result==1){
				//show();
				obj.html("已收藏");
				obj.addClass("alreadyDone");
				clickautohide("收藏成功",2);
			}else if(result.message!=""){
				clickautohide(message,3);
			}
		},"json");
	}
	
	//设置当前所选行Id
	function setCurrentLine(obj){
		if(obj.hasClass("alreadyDone")){
			return false;
		}
		var id=obj.closest("li.lineItem").attr("data");
		if(obj.hasClass("refundAply")){
			getMaxRefundMoney(id);
		}
		$("#currentLineId").val(id);
		return true;
	}
	//修改退款申请
	function refundUpdateFormSubmit(){
		var money=$("#refundMoney").val();
		if(money==""||isNaN(money)){
			$("#addRefundTips").html("<font color='red'>请输入正确的退款金额</font>");
			return false;
		}
		var maxRefundMoney=$("#maxRefundMoney").html();
		if(maxRefundMoney==""||isNaN(maxRefundMoney)){
			$("#addRefundTips").html("<font color='red'>不满足退款条件，无法退款，详情请见易学网退款规则</font>");
			return false;
		}
		if(parseInt(maxRefundMoney)<parseInt(money)){
			$("#addRefundTips").html("<font color='red'>退款金额不能大于当前最大可退金额</font>");
			return false;
		}
		$("#addRefundTips").html("正在提交修改信息。。。");
		var random=parseInt(Math.random()*1000)+1000;
		window.setTimeout("window.location.href='';",random);
		return true;
	}
	
	//获取最大可退款金额
	function getMaxRefundMoney(orderId){
		$.post(_appRoot+"/userCenter/maxRefundMoney",{orderId:orderId},function(result){
			if(result==null || result.result==null){
				$("#addRefundTips").html("<font color='red'>网络连接失败，请尝试刷新页面</font>");
			}
			if(result.result==0){
				$("#addRefundTips").html("<font color='red'>"+result.message+"</font>");
			}
			if(result.result==1){
				$("#maxRefundMoney").html(result.maxMoney);
			}
		},"json");
		
		
	}
	

	//取消订单-订单详情页面
	function cancelOrderForFast(obj){
		
		if(!confirm("您确定要取消该订单吗？")){
			return ;
		}
		var orderId=obj.attr("data");
		$.post("removeGoodsOrder",{orderId:orderId},function(result){
			//alert(result.message);
			if(result.result==1){
				window.location.href=_appRoot+"/userCenter/studentOrderDetail?id="+orderId;
			}
		},"json");
	}
	
	//删除讲师
	function deleteTeacherSubmit(){
		var purchasedId=$("#currentLineId").val();
		$('.cd-popup1').removeClass('is-visible');
		$.post("removePurchasedTeacher",{id:purchasedId},function(result){
			if(result==null || result.result==null){
				clickautohide("error",3);
			}
			if(result.result==0){
				clickautohide(result.message,3);
			}
			if(result.result==1){
				$("#lineItem_"+purchasedId).remove();
			}
		},"json");
		
		
		
	}
	
	//从收藏夹删除商品
	function deleteUserCollection(){
		var collectionId=$("#currentLineId").val();
		$('#deleteGoodsBox').fadeOut(300);
		$('#deleteGoodsBox .cd-popup-container').fadeOut(300);
		$.post("deleteUserCollection",{collectionId:collectionId},function(result){
			if(result==null || result.result==null){
				clickautohide("error");
			}
			if(result.result==0){
				clickautohide(result.message,3);
			}
			if(result.result==1){
				$("#lineItem_"+collectionId).remove();
			}
		},"json");
		
	}
	
	//从收藏夹加入购物车
	function addShoppingCartFromCollection(obj){
		if(obj.hasClass("alreadyDone")){
			return ;
		}
		var collectionId=obj.closest(".lineItem").attr("data");
		$.post("addShoppingCartFromCollection",{collectionId:collectionId},function(result){
			if(result==null || result.result==null){
				clickautohide("error",3);
			}
			if(result.result==0){
				clickautohide(result.message,3);
			}
			if(result.result==1){
				clickautohide("成功加入购物车",2);
				obj.addClass("alreadyDone").html("已加入购物车");
			}
		},"json");
	}
	
	//从评价列表加入购物车
	function addShoppingCartFromAppraiseList(obj){
		if(obj.hasClass("alreadyDone")){
			return ;
		}
		var appraiseId=obj.closest(".lineItem").attr("data");
		$.post("addShoppingCartFromAppraiseList",{appraiseId:appraiseId},function(result){
			if(result==null || result.result==null){
				clickautohide("error",3);
			}
			if(result.result==0){
				clickautohide(result.message,3);
			}
			if(result.result==1){
				clickautohide("成功加入购物车",2);
				obj.addClass("alreadyDone").html("已加入购物车");
			}
		},"json");
	}
	
	//从订单列表加入到购物车
	function addShoppingCartFromOrderList(obj){
		if(obj.hasClass("alreadyDone")){
			return ;
		}
		var orderId=obj.closest(".lineItem").attr("data");
		$.post("addShoppingCartFromOrderList",{orderId:orderId},function(result){
			if(result==null || result.result==null){
				clickautohide("error",3);
			}
			if(result.result==0){
				clickautohide(result.message,3);
			}
			if(result.result==1){
				//alert("成功加入购物车");
				$('.cd-popup3').addClass('is-visible');
				obj.addClass("alreadyDone").html("已加入购物车");
			}
		},"json");
	}
	
	//最近选择的类别切换
	function lastUseToggle(){
		var html="未选择分类";
		var categoryId="-1";
		if($("#lastUseCheckBox").attr("checked")){
				$("#queryStr").attr("enable",false);
				$("#s,#op").closest("tr").addClass("hide");
				html=$("#lastUseList").find("option:selected").text();
				categoryId=$("#lastUseList").val();
		}else{
				$("#queryStr").attr("enable",true);
			if($("#queryStr").val()!=""){
					$("#op").closest("tr").removeClass("hide");
					var obj=$("#op").find("p.select");
					if(obj.length>0){
						html=obj.html();
						categoryId=obj.attr("data");
					}
			}else{
					$("#s").closest("tr").removeClass("hide");
					html=$("#sh p").html()+" > "+$("#ch p").html()+" > "+$("#qu p").html();
					categoryId=$("#qu").attr("data");
			}
		}
		$("#finalValue").attr("data",categoryId).html(html);
		
	}
	
	//价格项点击事件注册
	function priceItemClickRegister(){
		$(".priceId").click(function(){
			if($(this).hasClass("disable")){
				return false;
			}
			if($(this).hasClass("select")){
				$(".select").removeClass("select");
				$(".priceId").removeClass("disable");
				
				var minPrice=$("#minPrice").val();
				var maxPrice=$("#maxPrice").val();
				if(minPrice==maxPrice){
					$(".s .span3 font").html("￥"+parseToYuan(maxPrice)+"");
					$(".mon font").html("￥"+parseToYuan(maxPrice)+"");
				}else{
					$(".s .span3 font").html("￥"+parseToYuan(minPrice)+"-"+parseToYuan(maxPrice));
					$(".mon font").html("￥"+parseToYuan(minPrice)+"-"+parseToYuan(maxPrice));
				}
				$("#goodsDetail_1").css('display','block');
				$("#goodsDetail_2").css('display','none');
		
				$("#selectedGoodsPriceId").val("");
			}else{
				$(this).closest("li").filter(".select").removeClass("select");
				$(this).addClass("select");
				var classStr=$(this).attr("class");
				var i=classStr.indexOf("priceId ");
				classStr=classStr.replace(" select","");
				classStr=classStr.substring(i+8);
				classStr="."+classStr.replace(/ /g,",.");
				$(".priceId").not(classStr).addClass("disable");
				var classes=classStr.split(",");
				var tips=[0,0,0,0,0];
				var num=0;
				var targetId=0;
				$(".select").each(function() {
                    for(var n=0;n<classes.length;n++){
						if($(this).attr("class").search(classes[n]))	
						{
							tips[n]+=1;
							}
						if(tips[n]==$(".select").length){num+=1;targetId=n}
						
					}
					if(num==1){
						var priceId=classes[targetId].substr(8);
						
						$.post("/browse/queryPriceById",{priceId:priceId},function(data){
							if(data.result==1){
								$(".s .span3 font").html("￥"+parseToYuan(data.price)+"");
								$(".mon font").html("￥"+parseToYuan(data.price)+"");
								
								if(data.goodsType==3){
									$("#goodsDetail_1").css('display','none');
									$("#goodsDetail_2").css('display','block');
									$("#goodsDetail_2").find("#attr1").html(data.condition2);
									$("#goodsDetail_2").find("#attr2").html(data.condition3);
									$("#goodsDetail_2").find("#attr3").html(data.endDate+"分钟");
									var html='<object><param name="wmode" value="transparent">';
									html+='<embed wmode="transparent"';
									html+='src="'+data.condition4+'"';
									html+=' allowFullScreen="true" quality="high" width="600" height="350" align="middle" allowScriptAccess="always" ';
									html+=' type="application/x-shockwave-flash" hidden="false">';
									html+='</embed></object>';
									$("#videoDiv").html(html);
								}else if(data.goodsType==4||data.goodsType==5){
									$("#goodsDetail_1").css('display','none');
									$("#goodsDetail_2").css('display','block');
									//$("#goodsDetail_2").find("#attr1").html("作者："+data.condition1);
									$("#goodsDetail_2").find("#attr2").html("格式："+data.condition2);
									$("#goodsDetail_2").find("#attr3").html("大小："+data.condition3);
								}
								
								
								
								}
							},"json");
						
					$("#selectedGoodsPriceId").val(priceId);
							}
                });
				
			}
		});
	}
	
	//检查输入是否为纯数字
	function checkisNumber(obj){
		if(isNaN(obj.val())){
			obj.val("");
		}
		
	}

	//加载top导航栏的购物栏数量
	/*function loadingTopShoppingCart(){
		var goodsPriceIds=[];
		var ids=getCookie("shoppingCart");
		if(ids!=null && ids !=""){
			goodsPriceIds=getCookie("shoppingCart").split(",");
		}
		if($("input#top_user_login_tag").length>0){
			//已登录
			$.post(_appRoot+"/userCenter/loadingShoppingCart",{goodsPriceIds:goodsPriceIds},function(result){
				if(result!=null && result.result==1){
					setCookie("shoppingCart","");
					$(".cart_top_num").html(result.sum);
				}
			},"json");
		}else{
			//未登录
			$(".cart_top_num").html(goodsPriceIds.length);
		}
		
	}*/



	
	//加载购物车
	function loadingShoppingCart(){
		var goodsPriceIds=[];
		var ids=getCookie("shoppingCart");
		if(ids!=null && ids !=""){
			goodsPriceIds=getCookie("shoppingCart").split(",");
		}
		if($("input#top_user_login_tag").length>0){
			//已登录
			$.post(_appRoot+"/userCenter/loadingShoppingCart",{goodsPriceIds:goodsPriceIds},function(result){
				if(result!=null && result.result==1){
					setCookie("shoppingCart","");
					$(".cart_num").html(result.sum);
					$(".cart_top_num").html(result.sum);
				}
			},"json");
		}else{
			//未登录
			var goodsSum = 0;
			for(var i=0;i<goodsPriceIds.length;i++){
				goodsSum += parseInt(goodsPriceIds[i].split("_")[1]);
			}
			$(".cart_num").html(goodsSum);
			$(".cart_top_num").html(goodsSum);
		}
		
	}
	
	//从浏览三级页面加入收藏夹
	function addUserCollectionFromBrowse(){
		if($("input#top_user_login_tag").length>0){
			
			//判断商品能否加入收藏夹
			var userId = $("#top_user_login_tag").val();
			var teacherId = $("#teacherId").val();
			if(userId==teacherId){
				clickautohide("不能收藏自己发布的商品",1);
				return false;
			}
			
			var goodsId=$("#goodsId").val();
			if(isNaN(goodsId)){
				goodsId=-1;
			}
			//已登录
			$.post("../../userCenter/addUserCollectionFromBrowse",{goodsId:goodsId},function(result){
				
				if(result!=null&&result.result==1){
					clickautohide("已加入收藏夹",2);
					$(".collect").find("a").attr("href","javascript:void(0);").find("img").attr("src",_appRoot+"/images/collect_2.png");
					$(".collect").find("a").find("span").text("已收藏");
				}else{
					clickautohide(result.message,3);
				}
				
			},"json");
		}else{
			//未登录
		}
		return false;
	}
	
	//从浏览三级页面加入购物车
	function addShoppingCartFromBrowse(max){
		var goodsPriceId=selectDefaultGoodsPrice(max);
		var goodsPriceSum=parseInt($("#goodsPriceSum").val());
		
		
		if(isNaN(goodsPriceId) || goodsPriceId==""){
			clickautohide("未选择价格",1);
			return false;
		}
		
		if($("input#top_user_login_tag").length>0){
			var userId = $("#top_user_login_tag").val();
			var teacherId = $("#teacherId").val();
			if(userId==teacherId){
				clickautohide("不能将自己的商品加入购物车",1);
				return false;
			}
			//已登录
			$.post("../../userCenter/addShoppingCartFromBrowse",{goodsPriceId:goodsPriceId,sum:goodsPriceSum},function(result){
				if(result!=null&&result.result==1){
					clickautohide("已加入购物车",2);
					var sum=$(".cart_num").html();
					if(isNaN(sum)){
						sum="0";
					}
					$(".cart_num").html(parseInt(sum)+goodsPriceSum);
					$(".cart_top_num").html(parseInt(sum)+goodsPriceSum);
				}else{
					clickautohide(result.message,3);
				}
				
			},"json");
		}else{
			//未登录
			var ids=getCookie("shoppingCart");
			if(ids==null ||ids==""){
				setCookie("shoppingCart",goodsPriceId+"_"+goodsPriceSum);
				clickautohide("成功添加至购物车",2);
				var sum=$(".cart_num").html();
				if(isNaN(sum)){
					sum="0";
				}
				$(".cart_num").html(parseInt(sum)+goodsPriceSum);
				$(".cart_top_num").html(parseInt(sum)+goodsPriceSum);
				return false;
			}
			var goodsPriceIds=ids.split(",");
			for(var i=0;i<goodsPriceIds.length;i++){
				var flag = goodsPriceIds[i].indexOf(goodsPriceId+"_");
				if(flag==0){
					clickautohide("商品已存在购物车内",1);
					return false;
				}
			}
			goodsPriceIds.push(goodsPriceId+"_"+goodsPriceSum);
			setCookie("shoppingCart",goodsPriceIds);
			clickautohide("成功添加至购物车",2);
			var sum=$(".cart_num").html();
			if(isNaN(sum)){
				sum="0";
			}
			$(".cart_num").html(parseInt(sum)+goodsPriceSum);
			$(".cart_top_num").html(parseInt(sum)+goodsPriceSum);
		}
		return false;
	}
	
	//立即购买
	function previewOrder(max){
		var userId = $("#top_user_login_tag").val();
		var teacherId = $("#teacherId").val();
		if(userId==teacherId){
			clickautohide("不能购买自己发布的商品",1);
			return false;
		}
		
		
		var goodsPriceId=selectDefaultGoodsPrice(max);
		if(isNaN(goodsPriceId) || goodsPriceId==""){
			clickautohide("未选择价格",1);
			return false;
		}
		var sum=$("#goodsPriceSum").val();
		window.location.href=_appRoot+"/charge/auth/previewOrder?ids="+goodsPriceId+"_"+sum;
	}
	
	//选择默认的商品价格
	function selectDefaultGoodsPrice(max){
		var goodsPriceId=$("input#selectedGoodsPriceId").val();
		if(isNaN(goodsPriceId) || goodsPriceId==""){
			var tag=1;
			for(var i=1;i<=max;i++){
				if($(".priceCondition"+i).find("span").length!=1){
					tag=0;
					break;
				}
			}
			if(tag==1){
				var idStr=$(".priceCondition1").find("span").attr("class");
				arr=idStr.split(" ");
				goodsPriceId=arr[1].replace("priceId","");
			}
		}
		return goodsPriceId;
	}
	
	//加载右侧菜单的明细列表
	function loadRightMenuDetailList(type){
		if(type=="message_list"){
			loadShoppingCartDetailList();
		}else if(type=="mpbtn_wdsc"){
			loadUserCollectionDetailList();
		}
	}
	
	//加载购物车详细列表
	function loadShoppingCartDetailList(){
		
		var goodsPriceIds=getCookie("shoppingCart");
		var idsArr;
		if(goodsPriceIds==null || goodsPriceIds==""){
			idsArr=new Array();
		}else{
			idsArr=goodsPriceIds.split(",");
		}
		$.post(_appRoot+"/userCenter/loadShoppingCartDetailList",{"goodsPriceIds":idsArr},function(result){
			if(result!=null && result.result==1){
				var html="";
				var list=result.list;
				var moneySum=0;
				var goodsSum=0;
				for(var i=0;i<list.length;i++){
					html+='<li class="cart_item" id="cartItem'+list[i].firstGoodsPrice.goodsPriceId+'" data="'+list[i].firstGoodsPrice.goodsPriceId+'">';
						html+='<input class="cart_check_item" onclick="cartCheckItemClick()" type="checkbox" style="vertical-align:-2px; float:left" i="'+parseToYuan(list[i].firstGoodsPrice.price)+'" data="'+list[i].salesSum+'">';
						html+='<div class="cart_item_pic"><a href="'+_queryGoods+list[i].goodsId+'"><img src="'+_picRoot+list[i].mainIco+'" /></a></div>';
						html+='<div class="cart_item_desc">';
							html+='<a href="'+_queryGoods+list[i].goodsId+'" class="cart_item_name">'+list[i].goodsName+'</a>';
							html+='<div class="cart_item_sku"><span></span></div>';
							html+='<div class="cart_item_price"><span class="cart_price">￥'+parseToYuan(list[i].firstGoodsPrice.price)+'×'+list[i].salesSum+'</span><a href="javascript:deleteGoodsFromShoppingCart('+list[i].firstGoodsPrice.goodsPriceId+',\''+list[i].extendNote3+'\');">移除</a></div>';
						html+='</div>';
					html+='</li>';
					//moneySum+=parseFloat(list[i].firstGoodsPrice.price)*parseFloat(list[i].salesSum);
					goodsSum+=list[i].salesSum;
				}
				$("#rightCartCheckAll").attr("checked",false);
				$(".ibar_plugin_content .ibar_cart_product ul").html(html);
				$(".cart_handler_left .cart_price").html(goodsSum);
				$(".cart_handler_right").html('￥0.00');//parseToYuan(moneySum)
			}else{
				clickautohide(result.message,3);
			}
		},"json");
	}
	
	//加载收藏列表明细
	function loadUserCollectionDetailList(){
		if($("input#top_user_login_tag").length==0){
			$(".ibar_plugin_content .ibar_cart_product ul").html("尚未登录");
			return false;
		}
		
		$.post(_appRoot+"/userCenter/loadUserCollectionDetailList",function(result){
			if(result!=null && result.result==1){
				var html="";
				var list=result.list;
				for(var i=0;i<list.length;i++){
					html+='<li class="cart_item" id="cartItem'+list[i].goodsId+'" data="'+list[i].goodsId+'">';
						//html+='<input class="cart_check_item" type="checkbox" style="vertical-align:-2px; float:left" data="'+list[i].goodsId+'">';
						html+='<div class="cart_item_pic"><a href="'+_queryGoods+list[i].goodsId+'"><img src="'+_picRoot+list[i].mainIco+'" /></a></div>';
						html+='<div class="cart_item_desc">';
							html+='<a href="'+_queryGoods+list[i].goodsId+'" class="cart_item_name">'+list[i].goodsName+'</a>';
							html+='<div class="cart_item_sku"><span></span></div>';
							html+='<div class="cart_item_price"><span class="cart_price">￥'+parseToYuan(list[i].firstGoodsPrice.price)+'</span><a href="javascript:deleteGoodsFromUserCollection('+list[i].goodsId+',\''+list[i].extendNote3+'\');">移除</a></div>';
						html+='</div>';
					html+='</li>';
				}
				$(".ibar_plugin_content .ibar_cart_product ul").html(html);
			}else{
				clickautohide(result.message,3);
			}
		},"json");
	}
	
	
	//从购物车移除商品
	function deleteGoodsFromShoppingCart(id,shoppingCartId){
		var root=$("#cartItem"+id);
		if(isNaN(shoppingCartId) || shoppingCartId==""){
			var goodsPriceId=root.attr("data");
			var ids=getCookie("shoppingCart");
			if(ids!=null){
				if(ids.indexOf(goodsPriceId+",")>-1){
					ids=ids.replace(goodsPriceId+",","");
				}else if(ids.indexOf(","+goodsPriceId)>-1){
					ids=ids.replace(","+goodsPriceId,"");
				}else{
					ids="";
				}
				setCookie("shoppingCart",ids);
			}
			root.remove();
			var sum=$(".cart_num").html();
			$(".cart_num").html(parseInt(sum)-1);
			$(".cart_top_num").html(parseInt(sum)-1);
			cartCheckItemClick();
		}else{
			$.post(_appRoot+"/userCenter/deleteShoppingCart",{shoppingCartId:shoppingCartId},function(result){
				if(result!=null && result.result==1){
					root.remove();
					var sum=$(".cart_num").html();
					$(".cart_num").html(parseInt(sum)-1);
					$(".cart_top_num").html(parseInt(sum)-1);
					cartCheckItemClick();
				}else{
					clickautohide(message,3);
				}
			},"json");
		}
	}
		
		
	//从收藏夹移除商品
	function deleteGoodsFromUserCollection(id,collectionId){
		var root=$("#cartItem"+id);
		if(isNaN(collectionId) || collectionId==""){
			/*
			var goodsId=root.find("input:checkbox").attr("data");
			var ids=getCookie("shoppingCart");
			if(ids!=null){
				if(ids.indexOf(goodsPriceId+",")>-1){
					ids=ids.replace(goodsPriceId+",","");
				}else if(ids.indexOf(","+goodsPriceId)>-1){
					ids=ids.replace(","+goodsPriceId,"");
				}else{
					ids="";
				}
				setCookie("shoppingCart",ids);
			}
			*/
			root.remove();
		}else{
			$.post(_appRoot+"/userCenter/deleteUserCollection",{collectionId:collectionId},function(result){
				if(result!=null && result.result==1){
					root.remove();
				}else{
					clickautohide(message,3);
				}
			},"json");
		}
	}
	
	//右侧购物车多选按钮选择事件
	function cartCheckItemClick(){
		var selected=0,moneySum=0.00;
		$(".cart_check_item:checked").each(function(){
			selected++;
			moneySum+=parseFloat($(this).attr("i"))*$(this).attr("data");
		});
		$(".cart_handler_left .cart_price").html(selected);
		$(".cart_handler_right").html("￥"+parseInt2Float(moneySum));
	}
	
	//右侧购物车全选事件
	function cartCheckItemClickAll(){
		if($("#rightCartCheckAll:checked").length>0){
			$(".cart_check_item").each(function(){
				this.checked = "checked";
			});
		}else{
			$(".cart_check_item").attr("checked",false);
		}
		cartCheckItemClick();
	}
	
	
	//Enter键执行全局搜索
	function doPostQueryAllForEnterDown(e){
		if(e.keyCode==13){
			doPostQueryAll();
		}
	}
	
	//热词搜索
	function doPostQueryAllForHot(str){
		$("#queryKeysStr").val(str);
		doPostQueryAll();
	}
	
	//全局搜索
	function doPostQueryAll(){
		var str=$("#queryKeysStr").val();
		$("#queryStrForGoods").val(str);
		var goodsType;
		if(str.indexOf("在线")>-1){
			goodsType=0;
		}else if(str.indexOf("面授")>-1){
			goodsType=1;
		}else if(str.indexOf("辅导")>-1 || str.indexOf("1对1")>-1){
			goodsType=2;
		}else if(str.indexOf("视频")>-1){
			goodsType=3;
		}else if(str.indexOf("课件")>-1){
			goodsType=4;
		}else if(str.indexOf("题库")>-1){
			goodsType=5;
		}else if(str.indexOf("考证")>-1 || str.indexOf("考试")>-1){
			goodsType=6;
		}else{
			goodsType=$("#top_goodsType").val();
		}
		if(goodsType==null || goodsType==""|| isNaN(goodsType) || goodsType=="-1" ){
			goodsType="ok";
		}
		$("#top_goodsType").val(goodsType);
		$("#top_categoryName").val("1");
		$("#top_categoryId").val("1");
		$("#orderBy").val("");
		$("#priceZone").val("");
		$("#attribute3").val("");
		$("#attribute4").val("");
		$("#attribute5").val("");
		$("#attribute6").val("");
		$("#queryForm").attr("action","../search.htm"/*tpa=http://www.yxit.net/search.htm*/);
		$("#queryForm").submit();
	}
	
	//元转换成分
	function parseToFen(money){
		var fen=100*parseFloat(money);
		return parseInt(fen);
	}
	//分转换成元
	function parseToYuan(money){
		if(money==""){
			return 0;
		}
		money=parseInt(money);
		var append=money%100;
		if(append<10){
			append="0"+append;
		}
		return parseInt((money/100)+"")+"."+append;
	}
	
	//分转换成角
	function parseFenToJiao(fen){
		if(fen==""){
			return "0.0";
		}
		fen=parseInt(fen);
		var append= ((fen+5)/10)%10;
		return parseInt((fen/100)+"")+"."+append;
	}
	
	function parseInt2Float(money){
			money+="";
			if(money.indexOf(".")==-1){
				return money+".00";
			}else{
				var append = money.substring(money.indexOf(".")+1);
				if(append.length==1){
					return money+"0";
				}else{
					return money;
				}
			}
	}
	
	//去html标签
	function removeHTMLTag(str) {
        str = str.replace(/<\/?[^>]*>/g,''); //去除HTML tag
        str = str.replace(/[ | ]*\n/g,'\n'); //去除行尾空白
        str=str.replace(/&nbsp;/ig,'');//去掉&nbsp;
        return str;
    }
	
	//到第N页
	function topage(n){
		$(".pageForm").find(".page").val(n);
		$(".pageForm").submit();
	}
	
	//跳转至第N页
	function turnpage(){
		var pagenum=$("#pagenum").val();
		var maxPage=$(this).attr("id");
		if(pagenum=="" ||pagenum>maxPage){
			pagenum=maxPage;
		}
		topage(pagenum);
	}
	
	//获取时间戳的yyyy-MM-dd格式时间值
	function _getDateStr(time){
		var date;
		if(time==null){
			date=new Date();
		}else{
			date=new Date(parseInt(time));
		}
		var month=1+date.getMonth();
		if(month<10){
			month="0"+month;
		}
		var day=date.getDate();
		if(day<10){
			day="0"+day;
		}
		return date.getFullYear()+"-"+month+"-"+day;
	}
	
	
	/*
	初始化三级商品页面中的收藏按钮
	*/
	function initCollection(){
		
		if($("input#top_user_login_tag").length>0){
			var goodsId =  $("#goodsId").val();
			$.post(_appRoot+"/userCenter/ajax4CollectionCart",{goodsId:goodsId},function(result){
				if(result!=null && result.result==1){
					if(result.message){
						$(".collect").find("a").attr("href","javascript:void(0);").find("img").attr("src",_appRoot+"/images/collect_2.png");
						$(".collect").find("a").find("span").text("已收藏");
					}
				}
			},"json");
		}else{
			return;
		}
		
		
	}
	/**
	从侧边栏的购物车中直接结算
	*/
	function countFromBrowse(){
		var num=$(".cart_item :checked").length;
		if(num<=0){
			clickautohide("请选择您要结算的商品",3);
			return ;
		}
		var ids=$(".cart_item :checked").map(function(){
			var goodsPriceId=$(this).parent().attr("data");
			var sum=$(this).attr("data");
			return goodsPriceId+"_"+sum;
		}).get().join(",");
		window.location.href=_appRoot+"/charge/auth/previewOrder?ids="+ids;
	}
	//设置页面描述
	function getDescription(description){
		var content=removeHTMLTag($(description).text());
		content=content.substring(0,100);
		$("meta[name='description']").attr("content",content);
	}
	//统计输入框文本字数
	function countChar(textareaID,maxNum,spanID){
		var NowNum=$(textareaID).val().length;
		if(NowNum>maxNum){
			$(textareaID).val($(textareaID).val().substr(0,maxNum));
		}
		else{
			$(spanID).text(NowNum);	
		}
	}
